<?php
namespace product\service;

use product\service\interfaces\IFactoryService;
use common\service\CommonService;
use herosphp\core\Loader;

Loader::import('product.service.interfaces.IFactoryService');

/**
 * product(Service)接口实现
 * @package product\service
 * @author yangjian<yangjian102621@gmail.com>
 */
class FactoryService extends CommonService implements IFactoryService {

    public function getItem($condition, $fields, $order)
    {
        $item = parent::getItem($condition, $fields, $order);
        if ( !empty($item) ) {
            //计算厂家牌号数
            $gradeModel = Loader::model("Grade");
            $item['grade_num'] = $gradeModel->count(array('facid' => $item['id']));
        }
        return $item;
    }

    public function getItems($conditions, $fields, $order, $limit, $group, $having)
    {
        $items = parent::getItems($conditions, $fields, $order, $limit, $group, $having);
        if ( !empty($items) ) {
            $gradeModel = Loader::model("Grade");
            foreach ( $items as $key => $value ) {
                $items[$key]['grade_num'] = $gradeModel->count(array('facid' => $value['id']));
            }
        }

        return $items;
    }
}
